#include<stdio.h>
#include<stdlib.h>
#define max 100002 
long n,i;
typedef struct oto{
    long phat;
    long ngay;
    long index;
};
oto arr[max];
int sosanh(const void *a, const void *b){
    oto x=*(oto*)a;
    oto y=*(oto*)b;
    return (int)(x.ngay*y.phat-y.ngay*x.phat);
}
void input(){
    FILE *fp=fopen("SCHEDULE.INP","r");
    fscanf(fp,"%ld",&n);

    for(i=0;i<n;i++)fscanf(fp,"%ld",&arr[i].phat);
    for(i=0;i<n;i++)fscanf(fp,"%ld",&arr[i].ngay);
    for(i=0;i<n;i++)arr[i].index=i;
    qsort(arr,n,sizeof(oto),sosanh);
    fclose(fp);
}
long tienPhat(){
    long a=0,time=0;
    for(i=0;i<n;i++){
        time+=arr[i].ngay;
        a+=time*arr[i].phat;
    }
    return a;
}
void output(){
    FILE *fp=fopen("SCHEDULE.OUT","w");
    fprintf(fp,"%ld\n",tienPhat());
    for(i=0;i<n;i++){
        if(i>0)fprintf(fp," ");
        fprintf(fp,"%ld",arr[i].index+1);
    }
    fclose(fp);
}
int main(){
    input();
    output();
    return 0;
}
